<?php
final class Controller_Price extends Controller_Security{
    protected function Acquiescent(){
        $data=Database::GetRows('select * from app_price order by ID desc',array(
            'CurrentPage '=>Route::GetArguments('page'),
            'PageSize'=>100
        ));
        Template::Assign('Data',$data);
        Template::Display('price/list.html');
    }

    protected function Add(){
        $action=Route::GetArguments('action');
        if('save'===$action){
            Database::Insert('app_price',array(
                'Name'=>$_POST['name'],
                'Price'=>$_POST['price'],
                'Description'=>$_POST['description'],
                'OrderNumber'=>$_POST['ordernumber']
            ));
            header('location:./?application=admin&controller=price');
        }
        else{
            Template::Display('price/add.html');
        }
    }

    protected function Edit(){
        $action=Route::GetArguments('action');
        if('save'===$action){
            $id=$_POST['id'];
            Database::UpdateRowsByValue('app_price','ID',$id,array(
                'Name'=>$_POST['name'],
                'Price'=>$_POST['price'],
                'Description'=>$_POST['description'],
                'OrderNumber'=>$_POST['ordernumber']
            ));
            Template::Assign('ID',$id);
            Template::Assign('Name',$_POST['name']);
            Template::Assign('Price',$_POST['price']);
            Template::Assign('Description',$_POST['description']);
            Template::Assign('OrderNumber',$_POST['ordernumber']);
            Template::Assign('AlertContainerDisplaySwitch','block'); //警告容器
            Template::Assign('AlertContent','修改成功');             //警告内容
            Template::Display('price/edit.html');
        }
        else{
            $data=Database::GetRowByValue('app_price','ID',Route::GetArguments('id'));
            Template::Assign('ID',$data['ID']);
            Template::Assign('Name',$data['Name']);
            Template::Assign('Price',$data['Price']);
            Template::Assign('Description',$data['Description']);
            Template::Assign('OrderNumber',$data['OrderNumber']);
            Template::Assign('AlertContainerDisplaySwitch','none'); //警告容器
            Template::Assign('AlertContent','');                    //警告内容
            Template::Display('price/edit.html');
        }
    }

    protected function Delete(){
        $id=Route::GetArguments('id');
        Database::DeleteRowsByValue('app_price','ID',$id);
        header('location:'.$_SERVER['HTTP_REFERER']);
    }
}
?>
